package feeinterface.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ulwx.database.DbException;
import com.ulwx.tool.DbUtils;

import feeinterface.modeldb.BaseDynamicRegular;

public class BaseDynamicRegularDao {

	/**
	 * 根据省份ID获取动态验证规则
	 * 
	 * @param ProvinceID
	 * @return
	 * @throws DbException
	 */
	public static List<BaseDynamicRegular> getDyRegularByProvinceID(int ProvinceID
			,String carrier)
			throws Exception {
		return getDyRegularBy(ProvinceID,0, carrier);
	}

	/**
	 * 根据通道ID和省份ID获取动态验证规则
	 * 
	 * 
	 * @param ChannelID
	 * @param ProvinceID
	 * @return
	 * @throws DbException
	 */
	public static List<BaseDynamicRegular> getDyRegularBy(int ProvinceID,
			int ChannelID,String carrier) throws Exception {
		

		String sql = "SELECT * 	FROM BaseDynamicRegular WHERE " +
				"ProvinceID = ? and   Carrier=? ";
		Map<Integer, Object> args = new HashMap<Integer, Object>();
		args.put(1, ProvinceID);
		args.put(2, carrier);
		if(ChannelID>0){
			sql= sql+" and (ChannelID=? or ChannelID=0) order by ChannelID desc";
		    args.put(3, ChannelID);
		}else{
			sql= sql+" order by ChannelID desc";
		}
		

		List<BaseDynamicRegular> list = DbUtils.doQueryClass(null,
				BaseDynamicRegular.class, sql, args);
		return list;
		
	
		
	}
}
